#include <bits/stdc++.h>
using namespace std;
int a[100010];
int san[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= 3;
  }

  for (int i = 3; i <= n; i++) {
    san[i] = a[i] + a[i - 1] + a[i - 2];
  }
  int ans = INT_MAX;
  for (int i = 0; i <= 2; i++) {
    san[3] = (san[3] + i) % 3;
    for (int j = 0; j <= 2; j++) {
      san[3] = (san[3] + j) % 3;
      san[4] = (san[4] + j) % 3;
      int ci = i + j;
      for (int k = 3; k <= n; k++) {
        int delta = (3 - san[k]) % 3;
        ci += delta;
        san[k + 1] = (san[k + 1] + delta) % 3;
        san[k + 2] = (san[k + 2] + delta) % 3;
      }
      ans = min(ans, ci);
    }
  }
  cout << ans;

  return 0;
}